package sk.ygor.raynor.client.json.basetype;

import com.google.gwt.json.client.JSONNumber;
import com.google.gwt.json.client.JSONValue;
import sk.ygor.raynor.client.json.JSONSerializationException;

public class java_lang_Short_JSONSerializer extends BaseTypeSerializer<Short> {

    @Override
    protected Short deserializeNonNullValue(JSONValue jsonValue) {
        JSONNumber number = jsonValue.isNumber();
        if (number != null) {
            return (short) number.doubleValue();
        }
        throw new JSONSerializationException("Cannot create Short from: " + jsonValue);
    }

    @Override
    protected JSONValue serializeNonNullValue(Short javaValue) {
        return new JSONNumber(javaValue);
    }

}